package com.example.mushroom.controller;

import com.example.mushroom.entity.AlertRule;
import com.example.mushroom.service.AlertRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/alert-rules")
public class AlertRuleController {

    @Autowired
    private AlertRuleService alertRuleService;

    @PostMapping
    public int insertAlertRule(@RequestBody AlertRule alertRule) {
        return alertRuleService.insertAlertRule(alertRule);
    }

    @GetMapping("/{id}")
    public AlertRule selectAlertRuleById(@PathVariable Integer id) {
        return alertRuleService.selectAlertRuleById(id);
    }

    @GetMapping
    public List<AlertRule> selectAllAlertRules() {
        return alertRuleService.selectAllAlertRules();
    }

    @PutMapping
    public int updateAlertRule(@RequestBody AlertRule alertRule) {
        return alertRuleService.updateAlertRule(alertRule);
    }

    @DeleteMapping("/{id}")
    public int deleteAlertRuleById(@PathVariable Integer id) {
        return alertRuleService.deleteAlertRuleById(id);
    }

    @GetMapping("/page")
    public List<AlertRule> selectAlertRulesByPage(@RequestParam int offset, @RequestParam int limit) {
        return alertRuleService.selectAlertRulesByPage(offset, limit);
    }
}